home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Sound / AHI / Developer / examples / Low-level / Req-test / req-test.c < prev    next >
C/C++ Source or Header  |  1997-06-28  |  2KB  |  80 lines

  1.  
  2. /* Demo of AHI's Audio mode requester */
  3.  
  4. #include <devices/ahi.h>
  5. #include <dos/dos.h>
  6. #include <proto/exec.h>
  7. #include <proto/dos.h>
  8. #include <proto/ahi.h>
  9. //#include <stdio.h>
  10. #include <stdlib.h>
  11.  
  12. struct Library    *AHIBase;
  13. struct MsgPort    *AHImp=NULL;
  14. struct AHIRequest *AHIio=NULL;
  15. BYTE   AHIDevice=-1;
  16.  
  17. struct TagItem ReqFilterTags[] = {
  18. //    {AHIDB_Realtime, TRUE},   // Remove the FILESAVE modes (among others?)
  19.     {TAG_DONE,}
  20.   };
  21.  
  22. void cleanup(LONG rc)
  23. {
  24.   if(!AHIDevice)
  25.     CloseDevice((struct IORequest *)AHIio);
  26.   DeleteIORequest((struct IORequest *)AHIio);
  27.   DeleteMsgPort(AHImp);
  28.   exit(rc);
  29. }
  30.  
  31. void main(void)
  32. {
  33.   struct AHIAudioModeRequester *req;
  34.   BOOL res;
  35.  
  36.   if(AHImp=CreateMsgPort())
  37.     if(AHIio=(struct AHIRequest *)CreateIORequest(AHImp,sizeof(struct AHIRequest))) {
  38.       AHIio->ahir_Version = 2;
  39.       AHIDevice=OpenDevice(AHINAME,AHI_NO_UNIT,(struct IORequest *)AHIio,NULL);
  40.       }
  41.  
  42.   if(AHIDevice) {
  43.     Printf("Unable to open %s version 2\n",AHINAME);
  44.     cleanup(RETURN_FAIL);
  45.   }
  46.   AHIBase=(struct Library *)AHIio->ahir_Std.io_Device;
  47.  
  48.   req=AHI_AllocAudioRequest(
  49.       AHIR_SleepWindow,TRUE,
  50.       AHIR_UserData,999,
  51.       AHIR_PubScreenName,NULL,
  52.       TAG_DONE);
  53.  
  54.   res=AHI_AudioRequest(req,
  55.       AHIR_TitleText,       "Select a mode or cancel",
  56.       AHIR_NegativeText,    "Abort",
  57.       AHIR_DoMixFreq,       TRUE,
  58.       AHIR_DoDefaultMode,   TRUE,
  59.       AHIR_InitialAudioID,  0x20003,
  60.       AHIR_InitialMixFreq,  30000,
  61.       AHIR_FilterTags,      ReqFilterTags,
  62.       TAG_DONE);
  63.  
  64.   if(!res)
  65.   {
  66.     if(IoErr() == ERROR_NO_FREE_STORE)
  67.       Printf("AHI ran out of memory!\n");
  68.     else if(IoErr() == ERROR_NO_MORE_ENTRIES)
  69.       Printf("No available modes!\n");
  70.     else
  71.      Printf("Requester cancelled!\n");
  72.   }
  73.   else
  74.     Printf("Selected AudioMode: 0x%08lx, %ld Hz\n",req->ahiam_AudioID,req->ahiam_MixFreq);
  75.  
  76.   AHI_FreeAudioRequest(req);
  77.  
  78.   cleanup(RETURN_OK);
  79. }
  80.